# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/20 下午4:20
 @Author  : tgy
 
"""


def test01():
    """
    +: 两个列表组成一个大列表
    *: 构造n个列表组成的一个大列表
    """
    n1 = [1, 2, 3]
    n2 = [4, 5, 6]
    print(n1 + n2)
    print(n2 * 10)


def test02():
    ...
    n1 = [1, 2, 3]
    # 删除指定位置的元素
    # n1[1:2] = []
    # del n1[1,2]
    # n1.pop(1)
    print(n1)


class Stack:
    __slots__ = ['_nums']

    def __init__(self):
        self._nums = []

    def push(self, el):
        self._nums.append(el)

    def pop(self):
        self.__check()
        return self._nums.pop()

    def peek(self):
        self.__check()
        return self._nums[-1]

    def isEmpty(self):
        return len(self._nums) == 0

    # 私有方法在name前面加上 两个下划线
    def __check(self):
        if not self._nums:
            raise RuntimeError('stack is empty')


def test_stack():
    test02()
    stack = Stack()
    [stack.push(n) for n in range(1, 10)]
    while not stack.isEmpty():
        print(stack.pop())
    # print(stack.pop())
    print(dir(stack))


class Queue:
    __slots__ = ['_num']

    def __init__(self):
        self._num = []

    def __check(self):
        if not self._num:
            raise RuntimeError('queue is empty')

    def offer(self, el):
        self._num.append(el)

    def pop(self):
        self.__check()
        return self._num.pop(0)

    def peek(self):
        self.__check()
        return self._num[0]

    def __len__(self):
        return len(self._num)

    def is_empty(self):
        return len(self) == 0


def test_queue():
    ...
    queue = Queue()
    [queue.offer(n) for n in range(1, 10)]
    while len(queue):
        print(queue.pop())

if __name__ == '__main__':
    ...
    # test_stack()
    test_queue()
